import { Injectable } from "@angular/core";
import { HttpClient, HttpParams } from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})

export class CommidityWatermarkManageService {

  serviceUrls = {
    queryGoodsListUrl: '/goods/list/page', // 查询商品List
    querySelectedGoodsListUrl: '/goods/getGoodsByIdList', // 查询已选商品List
    queryGoodsTypeTreeUrl: '/goodstypes/list', // 查询商品分类tree
    queryGoodsBrandUrl: '/coupon/goodsTypeAndBrand', // 查询指定品牌

    queryGoodsWaterListUrl: '/recycleWatermark/list', // 查询商品水印List
    queryGoodsWaterDetailsUrl: '/recycleWatermark/details', // 查询商品水印详情
    saveGoodsWaterUrl: '/recycleWatermark/save', // 新增商品水印
    editGoodsWaterUrl: '/recycleWatermark/update', // 编辑商品水印
    queryConflictUrl: '/recycleWatermark/conflict' // 水印冲突验证
  }

  constructor(public httpClient: HttpClient) {}

  // 查询商品List
  getGoodsListData(params: any) {
    return this.httpClient.get(this.serviceUrls.queryGoodsListUrl, { params }).toPromise();
  }

  // 查询已选商品List
  getSelectedGoodsList(params: any) {
    return this.httpClient.post(this.serviceUrls.querySelectedGoodsListUrl, params).toPromise();
  }

  // 查询商品分类tree
  queryGoodsTypeTreeData() {
    return this.httpClient.get(this.serviceUrls.queryGoodsTypeTreeUrl).toPromise();
  }

  // 查询指定品牌
  queryGoodsBrandData() {
    return this.httpClient.get(this.serviceUrls.queryGoodsBrandUrl).toPromise();
  }

  // 查询商品水印List
  queryGoodsWaterList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryGoodsWaterListUrl, params).toPromise();
  }

  // 查询商品水印详情
  queryGoodsWaterDetails(params: any) {
    return this.httpClient.post(this.serviceUrls.queryGoodsWaterDetailsUrl, params).toPromise();
  }

  // 新增 | 编辑商品水印
  updateGoodsWaterData(params: any) {
    let url = this.serviceUrls.saveGoodsWaterUrl;
    if (params.id) {
      url = this.serviceUrls.editGoodsWaterUrl
    }
    return this.httpClient.post(url, params).toPromise();
  }

  // 水印验证冲突List
  queryConflictData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryConflictUrl, params).toPromise();
  }
}
